#include <iostream>
using namespace std;
 
int main()
{
    string str;
    cin >> str;
    int n = str.size(), res = -1;
    for(int i = 0; i < n; ++i)
    {
        if(i - 1 < n && str[i] == str[i + 1])
        {
            res = 2;
            break;
        }
        if(i - 2 < n && str[i] == str[i + 2])
        {
            res = 3;
        }
    }
    cout << res << endl;
    return 0;
}